<?php

//控制基类
class Controller extends Smarty
{
	//自动调用模板配置
	public function __construct()
    {
        // 配置Smarty  对象链形式
        $this->setTemplateDir('./views')
            ->setCompileDir('./runtime/views_c')
            ->setConfigDir('./configs')
            ->setCacheDir('./runtime/caches');

        //配置 模版变量的定界符   <{  }> 
        $this->left_delimiter = LEFT_D;
        $this->right_delimiter = RIGHT_D;
        $this->caching = CACHING; //开启缓存
        $this->cache_lifetime = CACHE_LIFETIME; //配置缓存的时间
    }

	/**
	 * 跳转方法
	 * @param  [str] $message [提示信息]
	 * @param  [str] $url     [跳转地址]
	 * @return null
	 */
	public function redirect($message, $url=null)
	{
		echo "<script>alert('{$message}')</script>";
		if(empty($url)) {
			echo "<script>history.back()</script>";
		} else {
			echo "<script>location.href='$url'</script>";
		}
	}

	public function __call($fun, $params)
	{
		header('HTTP/1.0 404 not found');
		echo '<h1>404 NOT FOUND</h1>';
		exit;
	}
}